﻿/*
#------------------------------------------------------------------------------
#-- Program Name:	[dbo].[fnBkp_GetBackupList_Label]
#-- Purpose:		Returns a list of backups for a database that are needed
#--					to restore a specific labeled backup
#--	Last Update:	08/02/2012
#--					For a complete history - please review comments in Version
#--					Control.
#------------------------------------------------------------------------------
*/
CREATE FUNCTION [dbo].[fnBkp_GetBackupList_Label]
(	
	@database_name			sysname,
	@label					nvarchar(255)
)
RETURNS @returntable TABLE 
(
	id							bigint,
	recovery_path_broken		bit,
	backup_set_id				int,
	db_backup_set_id			int,
	prev_tlog_backup_set_id		int,
	database_name				nvarchar(128),
	name						nvarchar(128),
	type						char(1),
	backup_start_date			datetime,
	has_bulk_logged_data		bit,
	backup_size					numeric(20,0),
	physical_device_name		nvarchar(260),
	file_exists					bit,
	database_backup_lsn			numeric(25,0),
	differential_base_lsn		numeric(25,0),
	checkpoint_lsn				numeric(25,0),
	fork_point_lsn				numeric(25,0),
	first_lsn					numeric(25,0),
	last_lsn					numeric(25,0),
	first_recovery_fork_guid	uniqueidentifier,
	last_recovery_fork_guid		uniqueidentifier
)
AS
BEGIN	

	INSERT INTO @returntable
		SELECT		id,
					recovery_path_broken,
					backup_set_id,
					db_backup_set_id,
					prev_tlog_backup_set_id,
					database_name,
					name,
					type,
					backup_start_date,
					has_bulk_logged_data,
					backup_size,
					physical_device_name,
					file_exists,
					database_backup_lsn,
					differential_base_lsn,
					checkpoint_lsn,
					fork_point_lsn,
					first_lsn,
					last_lsn,
					first_recovery_fork_guid,
					last_recovery_fork_guid
		FROM		[dbo].[fnBkp_GetBackupList](@database_name, NULL, NULL, @label) t1
		ORDER BY	id

	RETURN
	
END